<template>
	<view>
		<u-sticky bgColor="#fff">
			<u-tabs :list="list1" lineColor="#ff9341" :scrollable=false @click="changetab" :activeStyle="{
				    color: '#000000',
				    fontWeight: 'bold',
				    transform: 'scale(1.05)'
				}" :inactiveStyle="{
				            color: '#666666',
							fontWeight: '500',
				            transform: 'scale(1)'
				        }" itemStyle="height: 44px;"></u-tabs>
		</u-sticky>
		<view class="mainpadding2">
			<view class="flexcolumn" v-if="list.data.length==0">
				<view class="placeholderimage" style="margin-top: 200rpx;"></view>
				<view class="xiaohui margin_top main_size">暂无数据</view>
			</view>
			<view class="mainpadding_top ffffff radius" v-for="item in list.data" :key="item.id" @click="jumpdetail('/pages_mypage/dingdanxq?id=',item.id)">
				<view class="flexbetween">
					<view class="ershiba xiaohei fonweight">订单编号：{{item.order_no}}</view>
					<view class="xiaohong ershiba fonweight" v-if="item.state==1">待支付</view>
					<view class="xiaolv ershiba fonweight" v-if="item.state==2">已支付</view>
					<view class="xiaohui ershiba fonweight" v-if="item.state==3">已取消</view>
				</view>
				<view class="flexleft margin_top " :class="item.state==2?'':'xiahuaxian'">
					<image :src="item.dmkj_image_text" class="listleftimg radius margin_right2" mode=""></image>
					<view class="" style="width: 100%;">
						<view class="titletext xiaohei">{{item.dmkj_name}}</view>
						<view class="flexbetween margin_top" style="width: 100%;">
							<view class="xiaohuang ershiba">号：{{item.dmkj_hm}}</view>
							<view class="xiaohong smalltext ">
								<text>￥</text>
								<text class="titletext fonweight">{{item.pay_price}}</text>
							</view>
						</view>
					</view>
				</view>
				<view class="flexright margin_top" v-if="item.state==1 || item.state==3">
					<view class="listbtnhui margin_right" v-if="item.state==1" @click.stop="cancelItem(item.id,'/api/ordercl/cancelOrder')">取消订单</view>
					<view class="listbtnlan" v-if="item.state==1" @click.stop="buy(item)">立即支付</view>
					<view class="listbtnhui" v-if="item.state==3" @click.stop="delItem(item.id,'/api/ordercl/delOrder')">删除订单</view>
				</view>
			</view>
		</view>
		<moDal :message="modal" @modalSure="modalSure" @modalcancel="modalcancel"></moDal>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				list1: [{
						name: '全部',
						value: 0,
					},
					{
						name: '待支付',
						value: 1,
					},
					{
						name: '已支付',
						value: 2,
					}
				],
				tabsid: 0,
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				modal:{
					modalShow:false,
					title:"",
				},
				currentapi:"",
				currentid:""
			}
		},
		onShow() {
			this.init()
		},
		methods: {
			cancelItem(id,url){
				this.currentapi = url
				this.currentid = id
				this.modal.title="是否确认取消订单？"
				this.modal.modalShow = true
			},
			delItem(id,url){
				this.currentapi = url
				this.currentid = id
				this.modal.title="是否确认删除当前订单？"
				this.modal.modalShow = true
			},
			modalSure(){
				if(this.modal.title=="是否确认取消订单？"){
					this.cancelorder()
				}else if(this.modal.title=="是否确认删除当前订单？"){
					this.delOrder()
				}
				this.modalcancel()
			},
			modalcancel(){
				this.modal.modalShow = false
			},
			cancelorder(){
				httpRequest.request(this.currentapi, 'GET', {
					id: this.currentid,
				}).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						this.init()
					}
				})
			},
			delOrder(){
				httpRequest.request(this.currentapi, 'POST', {
					id: this.currentid,
				}).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						this.init()
					}
				})
			},
			buy(item){
				uni.navigateTo({
					url:"/pages_index/querendd?id="+item.dmkj_id+"&price="+item.pay_price+"&order_id="+item.id
				})
			},
			init(isPage, page) {
				let _this = this
				httpRequest.request('/api/ordercl/orderList', 'GET', {
					page: page || 1,
					limit: 12,
					state:this.tabsid
				}).then(res => {
					uni.stopPullDownRefresh()
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			changetab(e) {
				this.tabsid = e.value
				this.page = 1
				this.list.data = []
				this.init()
			},
		}
	}
</script>

<style>

</style>